from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect

from favorite.models import MusicFavorite, PostFavorite
from .models import TrendList
# Create your views here.

@login_required
def trend_delete(request, pk):
    redirect_to = request.GET.get('next', '')

    if request.method == 'GET':
        trend = TrendList.objects.filter(pk=pk)

        if trend:
            trend.delete()
        if redirect_to:
            return redirect(redirect_to)

    trend_list = TrendList.objects.filter(user=request.user).order_by('-trend_time')
    f_music_list = MusicFavorite.objects.filter(user=request.user)
    f_post_list = PostFavorite.objects.filter(user=request.user)

    return render(request, 'user/profile.html', context={'trend_list': trend_list,
                                                         'f_music_list': f_music_list,
                                                         'f_post_list': f_post_list})

